package cn.techwis.service;

import cn.hutool.json.JSONObject;
import cn.techwis.dto.RefundsDTO;
import cn.techwis.common.WxApi;
import cn.techwis.vo.InItVO;
import cn.techwis.vo.PayRefundsVO;
import cn.techwis.util.WxHttpUtil;

/**
 * 退款
 */
public class PayRefundsService extends Tservice {


    /**
     * 统一退款
     *
     * @param payRefundsVO
     * @param inItVO
     */
    public static final RefundsDTO payRefunds(PayRefundsVO payRefundsVO, InItVO inItVO) {
        validateObject(payRefundsVO, PayRefundsVO.PayRefunds.class, inItVO);
        JSONObject jsonObject = WxHttpUtil.requestPost("统一退款", WxApi.refunds.REFUNDS, payRefundsVO, inItVO.getPrivateKeyFileName(), inItVO.getMchId(), inItVO.getSerialNo());
        return refundsResult(jsonObject);
    }

    public static void main(String[] args) {
        PayRefundsVO payRefundsVO = new PayRefundsVO();
        payRefundsVO.setOut_refund_no("123");
        payRefundsVO.setOut_trade_no("123");
        payRefundsVO.setAmount(PayRefundsVO.AmountVO.builder().refund(1).total(1).currency("CNY").build());
        InItVO inItVO =new InItVO();
        inItVO.setPrivateKeyFileName("C:\\Users\\yando\\Desktop\\apiclient_key.pem");
        inItVO.setSerialNo("71B1200AE00607AA44A2EC99DB14387CF266C354");
        inItVO.setMchId("1505026761");
        payRefunds(payRefundsVO,inItVO);
    }
}
